package com.atguigu05._super.exer3;

/**
 * ClassName: PersonTest
 * Description:
 *
 * @Author liu
 * @Create 2024/10/27 22:44
 * @Version 1.0
 */
public class CheckAccount extends Account{
    private double overdraft;


    public CheckAccount(int id, double balance, double annuallnterestRate, double overdraft) {
        super(id, balance, annuallnterestRate);
        this.overdraft = overdraft;
    }

    public double getOverdraft() {
        return overdraft;
    }

    public void setOverdraft(double overdraft) {
        this.overdraft = overdraft;
    }

    public void withdraw(double amount){
        if(getBalance() >= amount ){
            //错误
            //getBalance() = getBalance() - amount;
            //正确
            //super调用父类amount类的withdrew方法
            super.withdraw(amount);
        } else if (getBalance()+overdraft >= amount) {
            overdraft -= amount - getBalance();
            super.withdraw(getBalance());
        }else{
            System.out.println("超过可透支限额");
        }
    }
}
